﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace BankRemoteSystem.GUI
{
    public partial class frmLogin : Form
    {
        public Entities.User us = new BankRemoteSystem.Entities.User();
        public frmLogin()
        {
            InitializeComponent();
        }

        private void btnLogin_Click(object sender, EventArgs e)
        {
            loginform();
            
        }

        public void loginform()
        {
            BL.UserBO cbo = new BL.UserBO();
            BL.AccountBO abo = new BL.AccountBO();
            Entities.User c = cbo.login(txtName.Text, txtPass.Text);
            Entities.Account acc = abo.getAccoutbyUserID(txtName.Text);
            if ((c == null) || (acc == null))
            {
                MessageBox.Show("Sai Username or Password or AccountType");
            }
            else
            {
                this.Visible = false;
                us = c;
                MessageBox.Show("Ban dang nhap thanh cong");
                Form1 newForm1 = new Form1();
                newForm1 = (Form1)this.MdiParent;
                newForm1.reportToolStripMenuItem.Enabled = true;
                newForm1.tlstlpmnuAccounts.Enabled = true;
                newForm1.logOutToolStripMenuItem.Enabled = true;
                
                //UserForm sf = new UserForm(acc);
                //sf.Show();
            }

            frmMain fm = new frmMain(c);
            fm.MdiParent = this.MdiParent;
            fm.WindowState = FormWindowState.Maximized;
            fm.Show();
        }
       
        private void frmLogin_Load(object sender, EventArgs e)
        {
            
        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            Application.Exit();
        }
    }
}
